
import {
  queryPromotionCommissionRank,
  queryPromotionCommissionRankNumber
} from "../../../../service/jb_promotion_service"
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    topSwiperIndex: 0,
    swiperType: "week",
    requestData: {
      page: 1,
      limit: 50,
      keyword: "",
      type: 'week',
      grade: 0,
      sortKey: "",
      isAsc: ''
    },
    dataList: [

    ],
    rankNum: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.queryPromotionRankNumber();
    this.queryPromotionRank();
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  topSwiperChange(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      topSwiperIndex: index,
      swiperType: index == 0 ? 'week' : "month"
    })
    this.queryPromotionRankNumber();
    this.queryPromotionRank();
  },

  searchInputChange(e) {
    this.setData({
      "requestData.keyword": e.detail.value,
    })
  },
  //开始搜索
  handleSearchAction() {
    console.log("JJLog:开始搜索了：" + this.data.requestData.keyword);
  },

  queryPromotionRank() {
    wx.showLoading();
    queryPromotionCommissionRank(this.data.requestData.page, this.data.requestData.limit, this.swiperType).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        this.setData({
          dataList: res.data || [],
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      console.error('JJLog:queryPromotionCommissionRank', err);
    })
  },
  queryPromotionRankNumber(isRefresh) {
    if (isRefresh) {
      wx.showLoading();
    }
    queryPromotionCommissionRankNumber(this.data.swiperType).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        this.setData({
          rankNum: res.data || null
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      console.error('JJLog:queryPromotionCommissionRankNumber', err);
    })
  },


  //下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      'requestData.page': 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.queryPromotionRank();
    this.queryPromotionRankNumber();
  },

})